<#--
  DTO 公共函数和宏定义
  
  包含：
  - 类型处理函数
  - 字段过滤逻辑
  - 通用工具函数
-->

<#-- 函数：提取简单类名 -->
<#function getSimpleClassName fullClassName>
  <#if fullClassName?? && fullClassName?contains(".")>
    <#return fullClassName?split(".")?last>
  <#else>
    <#return fullClassName!"String">
  </#if>
</#function>

<#-- 函数：去重并排序列表 -->
<#function uniqueSort list>
  <#assign result = []>
  <#list list?sort as item>
    <#if !result?seq_contains(item)>
      <#assign result = result + [item]>
    </#if>
  </#list>
  <#return result>
</#function>

<#-- 函数：判断是否为 BaseEntity 字段（需要跳过） -->
<#function isBaseEntityField columnName>
  <#assign baseFields = ["tenant_id", "create_by", "create_time", "create_date", 
                          "update_by", "update_time", "update_date", "deleted", "version"]>
  <#if columnName??>
    <#assign lowerName = columnName?lower_case>
    <#list baseFields as field>
      <#if lowerName == field>
        <#return true>
      </#if>
    </#list>
  </#if>
  <#return false>
</#function>

<#-- 函数：判断是否为日期/时间类型 -->
<#function isDateTimeType javaType>
  <#if javaType??>
    <#return javaType?contains("Date") || javaType?contains("LocalDateTime") || 
             javaType?contains("LocalDate") || javaType?contains("Timestamp")>
  </#if>
  <#return false>
</#function>

<#-- 宏：生成字段注释 -->
<#macro fieldComment comment propertyName>
    /**
     * ${comment!(propertyName!'field')}
     */
</#macro>

<#-- 宏：生成 Excel 注解 -->
<#macro excelFieldAnnotation comment propertyName index propertyNameLower>
    @ExcelField(name = "${comment!(propertyName!'field')}", index = ${index}<#if propertyNameLower?ends_with("time")>, dateFormat = "yyyy-MM-dd HH:mm:ss"</#if>)
</#macro>

<#-- 宏：生成 getter 方法 -->
<#macro generateGetter type propertyName comment>
    
    /**
     * 获取${comment!(propertyName!'field')}
     *
     * @return ${comment!(propertyName!'field')}
     */
    public ${type} get${propertyName?cap_first}() { 
        return this.${propertyName}; 
    }
</#macro>

<#-- 宏：生成 setter 方法 -->
<#macro generateSetter type propertyName comment>

    /**
     * 设置${comment!(propertyName!'field')}
     *
     * @param ${propertyName} ${comment!(propertyName!'field')}
     */
    public void set${propertyName?cap_first}(${type} ${propertyName}) { 
        this.${propertyName} = ${propertyName}; 
    }
</#macro>

